package Lab3;

import java.util.ArrayList;
import java.util.Scanner;

public class MyStack implements Cloneable {
    private ArrayList list = new ArrayList();

    public void push(Object o) {
        list.add(o);
    }

    public Object pop() {
        Object r = list.get(list.size() - 1);
        list.removeLast();
        return r;
    }

    public boolean isEmpty() {
        return list.isEmpty();
    }

    public Object peek() {
        return list.get(list.size() - 1);
    }

    public int search(Object o) {
        return list.lastIndexOf(o);
    }

    public int getSize() {
        return list.size();
    }

    public String toString() {
        return "MyStack: " + list;
    }

    public MyStack clone(){
//        return this;
        MyStack n = new MyStack();
        for(Object o:list){
            n.push(o);
        }
        return n;
    }
}

class TestMyStack {
    public static void main(String[] args) {
        int[] l = typeArray();
        MyStack a = new MyStack();
        for(int i:l){
            a.push(i);
        }
        System.out.println(a);
        MyStack b = a.clone();
        a.pop();
        System.out.println(b);
    }

    public static int[] typeArray(){
        Scanner scan = new Scanner(System.in);
        System.out.print("Type your array: ");
        String[] line = scan.nextLine().replaceAll("//s", "").split("[,.;]");
        int[] list = new int[line.length];
        for (int i = 0; i < line.length; i++) {
            list[i] = Integer.parseInt(line[i]);
        }
        return list;
    }
}
